package com.liss.lissaiagent.rag;


import com.liss.lissaiagent.loader.LoveAppDocumentLoader;
import jakarta.annotation.Resource;
import org.springframework.ai.document.Document;
import org.springframework.ai.embedding.EmbeddingModel;
import org.springframework.ai.vectorstore.SimpleVectorStore;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;

/**
 * @Author: Mr.Li
 * @CreateTime: 2025-10-11
 * @Description: 向量数据库配置
 * @Version: 1.0
 */
@Configuration

public class LoveAppVectorStoreConfig {

    @Resource
    private LoveAppDocumentLoader loader;

    @Resource
    private MykeywordEnricher mykeywordEnricher;


    @Bean
    VectorStore loveAppVectorStore(EmbeddingModel dashscopeModel, LoveAppDocumentLoader loveAppDocumentLoader){
        SimpleVectorStore simpleVectorStore = SimpleVectorStore.builder(dashscopeModel).build();
        List<Document> documents = loader.loadMarkdown();
        //自动注入元信息增强器
        List<Document> enrichDocument = mykeywordEnricher.enrichDocument(documents);
        simpleVectorStore.add(enrichDocument);
        return simpleVectorStore;
    }
}
